from fastapi import Header, HTTPException, Request, Depends
from urllib import parse
from app import conf

import logging

logger = logging.getLogger(__name__)


def check_is_allowed_url(request: Request):
    allowed_uris = conf.UNAUTH_URIS
    #url_split(request.url)
    is_allowed_uri = False
    is_verified = False
    err_text = 'unknown error'
    url_scheme = request.url.scheme
    url_path = request.url.path
    parsed_query = parse.parse_qs(request.url.query)
    #print('Token: %s' % request.query_params.get('token'))
    for url_pattern in allowed_uris:
        if url_path == url_pattern or (
            url_pattern.startswith("*") and url_path.endswith(url_pattern[1:])
        ) or (
            url_pattern.endswith("*") and url_path.startswith(url_pattern[:-1])
        ):
            is_allowed_uri = True
            logger.debug('allowed url: %s' % url_pattern)
    return is_allowed_uri
